package ca.ubc.cpsc210.waldo.model;

import java.util.HashSet;
import java.util.Set;

import ca.ubc.cpsc210.waldo.exceptions.IllegalBusStopException;
import ca.ubc.cpsc210.waldo.util.LatLon;

public class BusStop {
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + number;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BusStop other = (BusStop) obj;
		if (number != other.number)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.name;
	}

	int number;
	String name;
	LatLon latlon;
	Set<BusRoute> routes;
	
	public BusStop(int number, String name, LatLon latlon, Set<BusRoute> routes) {
		
		if (!String.valueOf(number).matches("\\d{5}") || String.valueOf(number).isEmpty() || String.valueOf(number).equals("")|| name.isEmpty() || name.equals(null) || latlon.isIllegal()  || latlon.equals(null) || routes.isEmpty() || routes.equals(null) || routes.equals(new HashSet<BusRoute>().add(new BusRoute("")))) {
			throw new IllegalBusStopException();
		}
		
		this.number = number;
		this.name = name;
		this.latlon = latlon;
		this.routes = routes;
		
	}
	
	public BusStop(int number) {
		
		if (!String.valueOf(number).matches("\\d{5}") || String.valueOf(number).isEmpty() || String.valueOf(number).equals("0")) {
			throw new IllegalBusStopException();
		}
		
		this.number = number;
		this.name = null;
		this.latlon = null;
	}
	
	public int getNumber() {
		return number;
	}
	
	public String getName() {
		return name;
	}
	
	public LatLon getLatLon() {
		return latlon;
	}
	
	public Set<BusRoute> getRoutes() {
		return routes;
	}
	
}
